import { BasicColumn, BasicTable, FormSchema, useTable } from "@/components/Table";
import { useTranslation } from "react-i18next";
import { patOrdersItemsApi } from "@/api/statisticalReport/outpatientFeeDailyReport";
import Toolbar from "@/components/ViewComponents/Toolbar";
import "./index.less";
import { Descriptions, Divider } from "antd";
import { useEffect, useState } from "react";
const { Item } = Descriptions;
const index = () => {
	const { t } = useTranslation();
	const en_vi = "statisticalReport.outpatientFeeDailyReport";
	const [total, setTotal] = useState<any>([]);
	const [cashPrice, setCashPrice] = useState<any>([]);
	const [patCardPrice, setPatCardPrice] = useState<any>([]);
	const schemas: FormSchema[] = [
		{
			label: t(`statisticalReport.outpatientPrescriptionFees.paymentTime`),
			field: "payDtime",
			component: "RangePicker"
		}
	];
	const columns: BasicColumn[] = [
		{
			title: t(`${en_vi}.item`),
			dataIndex: "bizName"
		},
		{
			title: t(`${en_vi}.amountCNY`),
			dataIndex: "totalPrice"
		}
	];
	const [registerTable] = useTable({
		api: patOrdersItemsApi.patOrdersItemsList,
		columns,
		useSearchForm: true,
		formConfig: {
			labelWidth: 120,
			schemas,
			showActionButtonGroup: true,
			showAdvancedButton: false,
			baseColProps: { span: 6 },
			actionColOptions: { span: 24 }
		},
		bordered: true,
		beforeFetch: value => {
			console.log(value);
			return {
				...value,
				status: 1
			};
		}
	});
	const getPatOrdersItems = async () => {
		const res = await patOrdersItemsApi.patOrdersItemsList({ status: 1 });
		console.log(res);
		let total: any = 0;
		res.list.forEach((item: any) => {
			total += item.totalPrice;
		});
		setCashPrice(res.cashPrice);
		setPatCardPrice(res.patCardPrice);
		setTotal(total);
	};
	const handlerToolbarAction = async (key: string) => {
		console.log(key);
	};
	useEffect(() => {
		getPatOrdersItems();
	}, []);
	return (
		<div className="page outpatientFeeDailyReport">
			<div className="page-content">
				<div className="block outpatient_table">
					<BasicTable register={registerTable}></BasicTable>
					<p>
						{t(`${en_vi}.total`)}：{total}
					</p>
				</div>
				<div className="block  outpatient_other">
					<Divider orientation="left">{t(`${en_vi}.including`)}</Divider>
					<Descriptions bordered column={4}>
						<Item label={t(`${en_vi}.cashPayment`)}>{cashPrice}</Item>
						<Item label={t(`${en_vi}.actualCashPaid`)}>{cashPrice}</Item>
						<Item label={t(`${en_vi}.cash`)}>{cashPrice}</Item>
						<Item label={t(`${en_vi}.medicalInsuranceOnBehalf`)}>{patCardPrice}</Item>
						<Item label={t(`${en_vi}.accountingAmount`)}>{patCardPrice}</Item>
						<Item label={t(`${en_vi}.total`)}>{patCardPrice}</Item>
					</Descriptions>
				</div>
			</div>
			<Toolbar action={handlerToolbarAction} btnList={["print"]} />
		</div>
	);
};

export default index;
